<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>内容管理</title>
<link rel="stylesheet" type="text/css" href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../../static/css/uploadify.css"/>
<link rel="stylesheet" type="text/css" href="../../static/js/WdatePicker/skin/WdatePicker.css">

<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<script type="text/javascript" src="../../static/js/jquery.uploadify.js"></script>
<script type="text/javascript" src="../../static/js/WdatePicker/WdatePicker.js"></script>


</head>
<body style="width: 100%;">
	<table id="easyui-datagrid" title="行业客户列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar" style="">
		<div class="easyuiSearch">
			<form id="tool_bar_form">
				<table cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="left">添加时间：</td>
						<td align="left">
							<input name="f_po_cdate_start" type="text" onClick="WdatePicker({skin:'default',dateFmt: 'yyyy-MM-dd HH:mm:ss'})" onkeydown="onpress();" value="" />
							--
							<input name="f_po_cdate_end" type="text" onClick="WdatePicker({skin:'default',dateFmt: 'yyyy-MM-dd HH:mm:ss'})" onkeydown="onpress();" value="" />
						</td>
						<td align="left">客户名称：</td>
						<td align="left">
							<input name="f_po_name" type="text" onkeydown="onpress();" value="" />
						</td>
					</tr>
					<tr>
						<td align="left">地区:</td>
						<td>
							<select id="prov" name="f_po_address_province" onchange="showCity(this);" style="width: 100px;">
								<option value="11">浙江省</option>
							</select>
							<select id="city" name="f_po_address_city" onchange="showCountry(this);" style="width: 100px;">
								<option value="">--请选择--</option>
							</select>
							<select id="country" name="f_po_address_country" style="width: 100px;">
								<option value="">--请选择--</option>
							</select>
						</td>
						<td align="left">客户属性：</td>
						<td align="left">
							<select name="f_po_industry">
								<option value="0">请选择</option>
								<option value="10">测试</option>
								<option value="9">公司</option>
								<option value="8">党政军</option>
								<option value="7">党建</option>
								<option value="6">监狱</option>
								<option value="5">医疗</option>
								<option value="4">学校</option>
								<option value="3">休闲</option>
								<option value="2">政企</option>
								<option value="1">酒店</option>
							</select>
						</td>
						<td align="left">
							<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search', plain:true" onclick="gotoSearch()">查询</a>
							
							<limits:uiAuth url="customer_add.jsp">
							<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add', plain:true" onclick="add()">新增</a>
							</limits:uiAuth>
							<!-- <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-add', plain:true" onclick="batch_add()">终端控制</a> -->
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div style="margin-bottom: 5px">
			<!-- <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delete();" iconCls="icon-cut" plain="true">删除</a>  -->
		</div>
	</div>
	
	<div id="dlg" class="easyui-dialog" style="width: 950px; height: 600px; padding-top: 0px;" data-options="title:'客户修改', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0" style="width: 100%; height: 99%;"></iframe>
	</div>
	
	<div id="addUser" class="easyui-dialog" style="width: 600px; height: 600px; padding-top: 0px;" data-options="title:'用户新增', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0" style="width: 100%; height: 99%;"></iframe>
	</div>
	
	<div id="win" class="easyui-window" closed="true" modal="true" iconCls="icon-save" style="width:340px; height: 220px; left: 50%px;top: 30%;" title="账号批量导入">
		<input type="hidden" name="f_cc_companyid" val="0"/>
		<div class="easyui-layout" fit="true">
			<div region="north" border="true" style="height: 40;">
				<a class="easyui-linkbutton" style="line-height: 20px; padding-bottom: 3px;" iconCls="icon-undo" plain="true" target="_blank" rel="noopener noreferrer" href="../../static/excel/行业客户账号批量导入模版.xlsx">下载模版&nbsp;</a>
			</div>
			
			<div region="center" border="true">
				<div>
					<p>
						<font size="6" style="font-weight: bold;color: gray;">批量导入说明:</font><br/>
						&nbsp;&nbsp;1. 请先下载模版并填写账号<br/>
						&nbsp;&nbsp;2. 导入文档<br/>
					</p>
				</div>
			</div>
			
			<div region="south" border="false" style="text-align:left;height:40px;padding: 3px">
				<input id="uploadFile2"  type="file" name="file"/>
			</div>
			
		</div>
	</div>
	
	<script type="text/javascript">
		/* "use strict" */
		
		var $tool_bar_form = $("#tool_bar_form");
		
		var queryParams;
		function EasyuiDatagrid() {
			$("#easyui-datagrid").datagrid({
				url: '../../pms/orgVo_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'id',checkbox:true},
					{field:'f_po_id',title:'编号',align:'center',width:50},
					{field:'f_po_name',title:'客户名称',align:'center',width:200},
					{field:'f_po_address',title:'地区',align:'center',width:180,
						formatter:function(value,row,index){
							var wholeAddress = "";
							if(row.f_po_address) {
								var areaArr = row.f_po_address.split("-");
								if(areaArr[0]) {
									wholeAddress += provice[areaArr[0]].name;
									if(areaArr[1]) {
										wholeAddress += provice[areaArr[0]]["city"][areaArr[1]].name;
										if(areaArr[2]) {
											wholeAddress += provice[areaArr[0]]["city"][areaArr[1]]["districtAndCounty"][areaArr[2]];
										}
									}
								}
							}
							return wholeAddress;
						}
					},
					{field:'f_po_industry',title:'所属行业',align:'center',width:80,
						formatter:function(value,row,index){
							var result ="未知";
							//客户所属行业 1：酒店 2：政企 3：休闲 4：学校 5：医疗 6：监狱 7：党建 8：党政军 9：公司
							switch(row.f_po_industry) {
								case 0: 
									result = "无";
									break;
								case 1: 
									result = "酒店";
									break;
								case 2: 
									result = "政企";
									break;
								case 3: 
									result = "休闲";
									break;
								case 4: 
									result = "学校";
									break;
								case 5: 
									result = "医疗";
									break;
								case 6: 
									result = "监狱";
									break;
								case 7: 
									result = "党建";
									break;
								case 8: 
									result = "党政军";
									break;
								case 9: 
									result = "公司";
									break;
								case 10: 
									result = "测试";
									break;
								default: 
									break;
							}
							
							return result;
						}
					},
					{field:'f_po_channel',title:'虚拟频道',align:'center',width:80},
					{field:'f_po_channel_status',title:'频道开关',align:'center',width:80,
						formatter:function(value,row,index){
							var str ="";
							if(row.f_po_channel) {
								if(row.f_po_channel_status == 1) {
									<limits:uiAuth url="update_vistual_status.do">
									str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="disableVistualChannel(\''+row.f_po_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">暂停</span></span></a>';
									</limits:uiAuth>
								} else if(row.f_po_channel_status == 2) {
									<limits:uiAuth url="update_vistual_status.do">
									str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="enableVistualChannel(\''+row.f_po_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-add l-btn-icon-left">启用</span></span></a>';
									</limits:uiAuth>
								}
							} else {
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="alert(\'请先开通虚拟频道\');" ><span class="l-btn-left"><span class="l-btn-text icon-help l-btn-icon-left">无</span></span></a>';
							}
							return str;
						}
					},
					{field:'f_po_status',title:'状态',align:'center',width:80,
						formatter:function(value,row,index){
							var result ="";
							switch(row.f_po_status) {
								case 1: 
									result = "上线";
									break;
								case 2: 
									result = "无效";
									break;
								case 5: 
									result = "待审批";
									break;
								case 6: 
									result = "审批不通过";
									break;
								default: 
									break;
							}
							return result;
						}
					},
					{field:'f_po_createAt',title:'添加时间',align:'center',width:150,
						formatter:function(value,row,index) {
							var str = "";
							if(value!=null)
								str = value.substring(0,19);
							return str;
						}	
					},
					{field:'_parent',title:'操作',align:'center',width:450,
						formatter:function(value,row,index){
							var str ="";
							
							if(row.f_po_id>216){
								//删除
								<limits:uiAuth url="org_del.do">
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="deleteCustomer(\''+row.f_po_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-remove l-btn-icon-left">删除</span></span></a>';
								</limits:uiAuth>
								
								//修改
								<limits:uiAuth url="customer_update.jsp">
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="editCustomer(\''+row.f_po_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">修改</span></span></a>';
								</limits:uiAuth>
								
								//详情
								<limits:uiAuth url="customer_info.jsp">
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="show(\''+row.f_po_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-search l-btn-icon-left">详情</span></span></a>';
								</limits:uiAuth>
								
								//账号(批量)导入
								<limits:uiAuth url="insert_batch_content.do">
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="batch_add(\''+row.f_po_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">账号导入</span></span></a>';
								</limits:uiAuth>
								
								
								/* str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="show(\''+row.f_cc_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-edit l-btn-icon-left">账号批量删除</span></span></a>'; */
								
								//开通虚拟频道
								if(!row.f_po_channel) {
									<limits:uiAuth url="open_vistual_channel.do">
									str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="openVistualChannel(\''+row.f_po_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">开通虚拟频道</span></span></a>';
									</limits:uiAuth>
								}
							}
							
							
 							if(row.f_po_status == 1) {
 								<limits:uiAuth url="orgUser_add.jsp">
								str+= '<a class="easyui-linkbutton l-btn l-btn-plain" href="javascript:void(0);" plain="true" onclick="addUser(\''+row.f_po_id+'\');" ><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left">新增管理员</span></span></a>';
								</limits:uiAuth>
 							} 
							return str;
						}
					}
				]],
				singleSelect:false,
				pagination:true,
				pageList:[10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar',
			});
		}
		
		function getGueryParams(){
			return {
				f_po_cdate_start : $tool_bar_form.find("input[name='f_po_cdate_start']").val(),
				f_po_cdate_end : $tool_bar_form.find("input[name='f_po_cdate_end']").val(),
				f_po_address_province : $tool_bar_form.find("select[name='f_po_address_province']").val(),
				f_po_address_city : $tool_bar_form.find("select[name='f_po_address_city']").val(),
				f_po_address_country : $tool_bar_form.find("select[name='f_po_address_country']").val(),
				f_po_name : $tool_bar_form.find("input[name='f_po_name']").val(),
				f_po_industry : $tool_bar_form.find("select[name='f_po_industry']").val()
			};
		}
		
		$(function(){
			new EasyuiDatagrid();
		});
		
		var gotoSearch = function(){
			$("#easyui-datagrid").datagrid('reload',getGueryParams());
		};
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
			if (event.keyCode == 13){  
				gotoSearch($('#easyui-treegrid'));
			}
		}
		
		function show(id){
			openDialog($('#dlg'),'customer_info.jsp?f_po_id='+id);
		}
		
		function add(){
			openDialog($('#dlg'),'customer_add.jsp');
		}
		
		function editCustomer(id){
			openDialog($('#dlg'),'customer_update.jsp?f_po_id='+id);
		}
		
		function review(f_po_id) {
		}
		
		function addUser(f_po_id){
			openDialog($('#addUser'),'orgUser_add.jsp?f_po_id='+f_po_id);
		}
		
		function deleteCustomer(f_po_id) {
			$.messager.confirm("删除客户", "您确定要删除客户吗？", function (data) {
				if(data) {
					$.ajax({
						url:"../../pms/org_del.do",
						data: {
							f_po_id : f_po_id
						},
						dataType: "json",
						type: "POST",
						success:function(data) {
							if(data.success){
								$.messager.alert("操作提示","删除成功!","info",function(){
									gotoSearch();
								});
							} else {
								$.messager.alert("操作提示","删除失败!","error");
							}
						}
					});
				}
			});
		}
		
		function disableVistualChannel(f_po_id) {
			$.messager.confirm("暂停虚拟频道", "您确定要暂停虚拟频道吗？", function (data) {
				if(data) {
					$.ajax({
						url: "../../pms/update_vistual_status.do",
						data: {
							f_po_id : f_po_id,
							f_po_channel_status : 2
						},
						dataType: "json",
						type: "POST",
						success: function(data) {
							if(data.flag == 1) {
								$.messager.alert("操作提示", "暂停成功！");
								gotoSearch();
							} else {
								$.messager.alert("操作提示", "暂停失败！","error");
							}
						}
					});
				}
			});
		}
		
		function enableVistualChannel(f_po_id) {
			$.messager.confirm("启用虚拟频道", "您确定要启用虚拟频道吗？", function (data) {
				if(data) {
					$.ajax({
						url: "../../pms/update_vistual_status.do",
						data: {
							f_po_id : f_po_id,
							f_po_channel_status : 1
						},
						dataType: "json",
						type: "POST",
						success: function(data) {
							if(data.flag == 1) {
								$.messager.alert("操作提示", "启用成功！");
								gotoSearch();
							} else {
								$.messager.alert("操作提示", "启用失败！","error");
							}
						}
					});
				}
			});
		}
		
		function openVistualChannel(f_po_id, default_val) {
			$.messager.prompt("开通虚拟频道", "请输入需要开通的虚拟频道后点击确定按钮。", function (data) {
				if(data !== undefined) {
					if(!data || data.length >= 10 || data.length <= 0) {
						alert("虚拟频道不能为空，并且长度不能超过10。");
						openVistualChannel(f_po_id, data);
						return false;
					} else {
						$.ajax({
							url: "../../pms/open_vistual_channel.do",
							data: {
								f_po_id : f_po_id,
								f_po_channel : data,
								f_po_channel_status : 1
							},
							dataType: "json",
							type: "POST",
							success: function(data) {
								if(data.flag == 1) {
									$.messager.alert("操作提示", "操作成功！");
									gotoSearch();
								} else {
									$.messager.alert("操作提示", "操作失败！","error");
									openVistualChannel(f_po_id, data);
								}
							}
						});
					}
				}
			});
			$(".messager-input").val(default_val);
		}
		
		$(function(){
			
			$('#win').window({
				onBeforeClose:function(){ 
					//window.location.reload();	
				}
			});
			initFileUpload("#uploadFile2", {});
		});
		
		function batch_add(f_po_id){
			$('#win').window('open');
			$("#win input[name='f_cc_companyid']").val(f_po_id);
		}
		
		function initFileUpload(inputId, params){
			var action = '../../content/industry_batch_insert_content.do;jsessionid=${pageContext.session.id}';
			$(inputId).uploadify({
				'swf'           :'../../swf/uploadify.swf',
				'uploader'      :action,
				'formData'      :params,
				'fileObjName'   :'uploadify',
				'cancelImg'     :"../../imgs/uploadify-cancel.png",
				'queueId'       :"fileQueue",
				'fileTypeDesc'  :"Excel File",
				'fileTypeExts'  :"*.xls; *.xlsx",//限制文件类型
				'auto'          :true,//是否自动上传
				'multi'         :false,//是否允许多文件上传
				'buttonText'    :"导入文档",
				'method'        :"POST",
				'onInit'        : function(){
				},
				'onUploadStart' : function(file){
						$(inputId).uploadify('settings','formData', {"f_cc_companyid" : $("#win input[name='f_cc_companyid']").val()});
						jQuery.messager.alert('批量导入','批量导入开始, 操作结果请稍后.');
				},
				'onUploadSuccess' : function(file,data,response) {
					if(data != null && data != undefined && data != ''){
						jQuery.messager.alert('批量导入',data);
					}
				},
				'onUploadError' : function(file, errorCode, errorMsg, errorString) {
					if(errorMsg == '302'){
						jQuery.messager.alert('批量导入','批量导入失败，请检查登录状态或者无此权限!');
					}
				}
			});
		}
	</script>
	
	<script type="text/javascript" src="../../static/js/city/city.js"></script>
	<script type="text/javascript" src="../../static/js/city/method01.js"></script>
</body>
</html>